package com.backend.demo1.controller;

import com.backend.demo1.config.ApiResponse;
import com.backend.demo1.models.User;
import com.backend.demo1.services.UserService;

// import cn.hutool.captcha.CaptchaUtil;
// import cn.hutool.captcha.CircleCaptcha;
// import cn.hutool.captcha.generator.RandomGenerator;

// import java.io.IOException;
// import jakarta.servlet.http.HttpServletResponse;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class UserController {

    @Autowired
    private UserService userService;
    
    @GetMapping("/users")
    public ResponseEntity<ApiResponse<List<User>>> getAllUsers() {
        List<User> users = userService.getAllUsers();
        return ResponseEntity.ok(new ApiResponse<>(200, "查询成功", users));
    }

    @PutMapping("/users/{id}")
    public ResponseEntity<ApiResponse<String>> updateUser(@PathVariable Long id, @RequestBody User user) {
        userService.updateUser(id, user);
        return ResponseEntity.ok(new ApiResponse<>(200, "更新成功", null));
    }

    @DeleteMapping("/users/{id}")
    public ResponseEntity<ApiResponse<String>> deleteUser(@PathVariable Long id) {
        userService.deleteUser(id);
        return ResponseEntity.ok(new ApiResponse<>(200, "删除成功", null));
    }
    @GetMapping("/users/{id}")
    public ResponseEntity<ApiResponse<User>> getUserWithDepartment(@PathVariable Long id) {
        User user = userService.getUserWithDepartmentById(id);
        return ResponseEntity.ok(new ApiResponse<>(200, "查询成功", user));
    }
}